# @Auther: cty
# @Date: 2019/10/31
# @Description: 数据库删除
# @version: 1.0

import pymysql

# 打开数据库连接
db = pymysql.connect("localhost", "cty", "123456", "TESTDB")

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# SQL 删除语句
sql = "DELETE FROM EMPLOYEE WHERE AGE > %d" % (20)
try:
   # 执行SQL语句
   cursor.execute(sql)
   # 提交修改
   db.commit()
except:
   # 发生错误时回滚
   db.rollback()

# SQL 查询语句
sql = "SELECT * FROM EMPLOYEE"
try:
   # 执行SQL语句
   cursor.execute(sql)
   # 获取所有记录列表
   results = cursor.fetchall()
   for row in results:
      print("update table :%s" %str(row))
except:
   print ("Error: unable to fetch data")

# 关闭数据库连接
db.close()



'''
# 结果：

'''